package com.qf.j2112.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @ProjectName: YiZhanXiYi
 * @Package: com.qf.j2112.config
 * @ClassName: RedisConfig
 * @Author: 宋晓博
 * @Description: description
 * @Date: 2022/4/22 16:21
 * @Version: 1.0
 */

@Configuration
public class RedisConfig {
    @Bean  //手工注入一个Jedi是Connection Factory的对象
    public JedisConnectionFactory getJedisConnectionFactory(){
        return new JedisConnectionFactory() ;
    }

    @Bean
    public RedisTemplate redisTemplate(){
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(getJedisConnectionFactory());
        //设值处理string类型数据的序列号转换器
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        return redisTemplate;
    }
}
